import os
from urllib import request
import ddddocr

ocr = ddddocr.DdddOcr(show_ad=False)

def ocrCaptchaUrl(url):
    try:
        rsp = request.urlopen(url)
        return ocr.classification(rsp.read())
    except Exception as e:
        print(e)
        return '{"status":"500"}'

# file_dir = 'D:/data/crawl-service/tmp/'
# for file in os.listdir(file_dir):
#     file_path = os.path.join(file_dir, file)
#     with open(file_path, 'rb') as f:
#         res = ocr.classification(f.read())
#         print(file_path, res)

# url = 'https://cdn.wenanzhe.com/img/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211226142325.png'
# print('result:', ocrCaptchaUrl(url) )



